<include file="header" />
<body>
<div class="wraper">
    <div class="top">
        <a href="javascript:history.go(-1);" class="iconfont icon-zuo pull-left"></a>
        <span class="pull-left">电费充值</span>
        <!--<a href="{BEESCRM::U('base/electricity/chargeLog',array('ele_id'=>$ele_id))}" class="pull-left text-right">历史充电</a>-->
        <a href="javascript:void(0);" class="iconfont icon-caidan-copy pull-left text-right"></a>
        <div class="sub-menu">
            <a href="{BEESCRM::U('base/electricitySr/chargeLog',array('ele_id'=>$ele_id))}" class="sub-menu-list"><span class="iconfont icon-czjl"></span>历史记录</a>
        </div>
    </div>
    <div style="background: #1C85B2;">
	    <p class="warnimg">截至{BEESCRM:$uploaddt} 剩余金额</p>
	    <div class="electric-note tb-mode">
	        <div class="tb-cell">
	            <p class="odd">{BEESCRM:$ele}元</p>
	            <p>{BEESCRM:$community_name} {BEESCRM:$building_name} {BEESCRM:$room_name}</p>
	        </div>
	        <div class="tb-cell search-btn text-right"><a href="{BEESCRM::U('base/electricitySr/query',array('ele_id'=>$ele_id))}">电量查询</a></div>
	    </div>
    </div>
    <div class="margin-top">
        <p class="form-box">
            <select id="community">
                <option value="0">请选择所在生活区</option>
                <volist name="community" id="vo">
                    <option value="{BEESCRM:$vo.community_id}" <if condition="$vo['community_id'] eq $community_id" >selected="selected"</if> data-num="{BEESCRM:$vo.community_code}">{BEESCRM:$vo.community_name}</option>
                </volist>
            </select>
            <span class="triangle"></span>
        </p>
        <p class="form-box">
            <select id="building">
                <option value="0">请选择楼幢</option>
            </select>
            <span class="triangle"></span>
        </p>
	    <p class="form-box">
            <select id="floor">
                <option value="0">请选择楼层</option>
            </select>
            <span class="triangle"></span>
        </p>
	    <p class="form-box">
            <select id="room">
                <option value="0">请选择房间</option>
            </select>
            <span class="triangle"></span>
        </p>
    </div>
    <div class="contain-box margin-top">
        <p class="amount">充值金额</p>
        <div class="tab-prize clearfix">
	      <!--  <span class="option sub-list checked" data-amount="0.01">0.01元</span>-->
            <span class="option sub-list " data-amount="30">30元</span>
            <span class="option sub-list" data-amount="60">60元</span>
            <span class="option sub-list" data-amount="90">90元</span>
            <span class="option sub-list" data-amount="120">120元</span>
            <span class="option sub-list" data-amount="300">300元</span>
        </div>
    </div>

	<div class="contain-box margin-top">
        <p class="amount" style="color: red;">温馨提示:</p>
		<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;请同学们尽量不要在凌晨0点—5点时间段充值电费，凌晨系统维护中，充值电费通电会有所延迟，给您带来不便，敬请谅解！</p>
    </div>

    <div class="btn-box">
	    <input type="hidden" id="ele_id" value="{BEESCRM:$ele_id}">
        <a href="javascript:void(0);" class="btn save">立即充值</a>
    </div>
	<input type="hidden" id="community_id" value="{BEESCRM:$community_id}">
	<input type="hidden" id="building_id" value="{BEESCRM:$building_id}">
	<input type="hidden" id="floor_id" value="{BEESCRM:$floor_id}">
	<input type="hidden" id="room_id" value="{BEESCRM:$room_id}">
</div>
<div >

</div>
<include file="commonJS" />
<script src="/assets/base/common/ajaxgetroominfo.js"></script>
<script>
	$(function(){
        $('.icon-caidan-copy').click(function(e){
            $('.sub-menu').toggleClass('show');
            e.stopPropagation();
        })
        $(document).click(function(){
            $('.sub-menu').removeClass('show');
        })
		//调用房间联动js
		ajaxgetroominfo(true,true,true);
		var community_id = $('#community_id').val();
		var building_id = $('#building_id').val();
		var floor_id = $('#floor_id').val();
		var room_id = $('#room_id').val();
		if(community_id){
			getBuildingInfo(community_id);
		}

		if(building_id){
			getFloorInfo(building_id);
		}

		if(floor_id){
			getRoomInfo(floor_id);
		}


		if(building_id){
			$('#building').val(building_id);
		}

		if(floor_id){
			$('#floor').val(floor_id);
		}

		if(room_id){
			$('#room').val(room_id);
		}

	});

    $('.tab-prize').on('click','.option',function(){
        if($(this).hasClass('other')){
            $(this).siblings().removeClass('checked');
            $(this).addClass('checked');
        }
        else{
            $(this).toggleClass('checked').siblings().removeClass('checked');
        }
    });

    /*提交订单*/
    $(document).on('click','.save',function(){
	    var myDate = new Date();
	    var wh = myDate.getHours();
	    if(wh>=0 && wh<=5){
		    $.tips('系统君正在维护（0:00-5:00），充值电费将延迟到账，晚安！', subOrder);
	    }else{
		    subOrder();
	    }
    });
	function subOrder(){
		var money = $('.checked').data('amount');
		var order_price = 0;
		var community_id = $("#community").val();
		var building_id = $("#building").val();
		var floor_id   = $("#floor").val();
		var room_name = $("#room").find("option:selected").data('name');
		var room_id = $("#room").val();
		var room_code = $("#room").find("option:selected").data('code');
		var building_code = $("#building").find("option:selected").data('num');
		var community_code = $("#community").find("option:selected").data('num');
		var ele_id = $('#ele_id').val();
		if(!room_id){
			$.alert('error','请选择寝室');
			return false;
		}

		if(money > 0 && money != 'undefined'){
			order_price = money;
		}else{
			$.alert('error','请选择充值金额');
			return false;
		}


		var info = {};
		info.community_id = community_id;
		info.building_id = building_id;
		info.floor_id = floor_id;
		info.room_id = room_id;
		info.room_name = room_name;
		info.room_code = room_code;
		info.building_code = building_code;
		info.community_code = community_code;
		if(room_code == '' || building_code == '' || community_code ==''){
			$.alert('error',"该寝室暂不能充值");
			return false;
		}
		info.order_amount = order_price;
		info.flag = 1;
		$.ajax({
			'url': "/base/electricitySr/index/ele_id/"+ele_id,
			'data': info,
			'dataType':'json',
			'type': 'POST',
			'async': false,
			success: function(data) {
				if (data.status == 'S') {
					window.location.href=data.url;
				}else{
					$.alert('error',data.message);
					return false;
				}
			}
		});
	}
</script>
</body>
</html>